<template>
  <div class="check-assist">
    <div class="tip-wrap">
      <div v-if="ruleList.length === 0" style="text-align: center;padding: 20px;">暂无被启用的质检规则</div>
      <div v-for="(item, index) in ruleList" style="border-bottom: 1px solid #ccc;padding: 14px; 0">
        <el-row :gutter="20" style="padding: 2px 0;">
          <el-col :span="6"><span>规则名称</span></el-col>
          <el-col :span="18"><strong>{{item.name}}</strong></el-col>
        </el-row>
        <el-row :gutter="20" style="padding: 2px 0;">
          <el-col :span="6"><span>规则评分</span></el-col>
          <el-col :span="18"><strong style="margin-right: 12px;">关联计分项：{{item.scoreConfig.parent.name}}</strong><strong style="margin-right: 12px;">{{item.scoreConfig.sub.name}}  分数：{{item.scoreConfig.sub.score}}</strong>  <strong>计分次数：{{item.scoreConfig.count}}</strong></el-col>
        </el-row>
        <el-row :gutter="20" v-for="(item, index) in item.ruleList" style="padding: 2px 0;">
          <el-col :span="6"><span>原子{{index + 1}}</span></el-col>
          <el-col :span="18">
            <el-row :gutter="20">
              <el-col :span="22">{{item.name}}</el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="22"><div class="ellipsis" :title="item.nameDetail">{{item.nameDetail}}</div></el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="padding: 2px 0;">
          <el-col :span="6"><span>原子逻辑</span></el-col>
          <el-col :span="18">
            <div v-for="the in item.ruleLogic">
              <strong style="margin-right: 12px;">{{the.strategyName}}</strong><span style="margin-right: 4px;" v-for="one in the.keys">{{one}}</span>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
  import {deepClone} from '@/utils/m7Utils.js'
  export default {
    name: 'CheckAssist',
    data () {
      return {
      }
    },
    methods: {
      getData (obj) {
        if (obj.type === 'less') {
          return '小于' + obj.max
        } else if (obj.type === 'greater') {
          return '大于' + obj.min
        } else {
          return obj.min + '-' + obj.max
        }
      }
    },
    props: {
      ruleRender: Array
    },
    beforeMount () {
    },
    computed: {
      ruleList () {
        let list = deepClone(this.ruleRender)
        let data = []
        let dataObj = {}
        list.forEach(item => {
          dataObj = {}
          dataObj.name = item.name
          dataObj.scoreConfig = item.scoreConfig
          dataObj.ruleLogic = item.ruleLogic
          dataObj.ruleLogic.forEach(one => {
            if (one.strategy === 'any') {
              one.strategyName = '满足任意一个'
            } else if (one.strategy === 'all') {
              one.strategyName = '满足全部'
            } else {
              one.strategyName = '不满足全部'
            }
          })
          dataObj.ruleList = item.ruleList
          dataObj.ruleList.forEach(item => {
            item.nameDetail = ''
            if (item.type === 'keywordCheck') {
              if (item.strategy === 'all') {
                item.nameDetail = '全部出现  ' + item.words.join()
              } else if (item.strategy === 'any') {
                item.nameDetail = '出现任意一个  ' + item.words.join()
              } else {
                item.nameDetail = '全部不出现  ' + item.words.join()
              }
            } else if (item.type === 'interrupt') {
              item.nameDetail = '抢段时间：' + this.getData(item.interruptTime) + '毫秒' + '    抢断次数：' + this.getData(item.interruptCount) + '次'
            } else if (item.type === 'firstResponse') {
              item.nameDetail = this.getData(item.responseTime) + '秒'
            } else if (item.type === 'talkSpeed') {
              item.nameDetail = this.getData(item.speedRange) + '秒'
            } else if (item.type === 'regCheck') {
              item.nameDetail = '正则表达式  ' + item.regStr
            } else if (item.type === 'talkInterval') {
              if (item.checkType === 'adjacent') {
                item.nameDetail = '不区分角色  ' + item.intervalTime + '秒'
              } else {
                if (item.distinctType === 'endTime') {
                  item.nameDetail = '不同角色之间  ' + '后一句结束时间  ' + item.intervalTime + '秒'
                } else {
                  item.nameDetail = '不同角色之间  ' + '前一句结束时间  ' + item.intervalTime + '秒'
                }
              }
            } else if (item.type === 'regRepeat') {
              item.nameDetail = '正则表达式  ' + item.regStr
            } else if (item.type === 'moodTest') {
            }
          })
          data.push(dataObj)
        })
        return data
      }
    }
  }
</script>
<style lang="stylus" scoped>
  .check-assist
    .tip-wrap
      max-height 300px
      overflow-y auto
      font-size 12px
</style>
